// const reqData = {
//     text: '生成一篇奥运会的新闻',
//     messages: [],
//     is_bots: []
// };
async function send(text, message, is_bots, callback) {
    // const url = "http://172.28.6.3:1762/context_batch_return";
    const url = "http://127.0.0.1:12355/api/knowledge_base_chat";
    const data = {
        text: text,
        message: message,
        is_bots: is_bots
    }
    const response = await fetch(url, {
        method: "POST",
        body: JSON.stringify(data),
        headers: {
            "Content-Type": "application/json"
        }
    })
    const reader = response.body.getReader();
    const decoder = new TextDecoder('utf-8');
    while (true) {
        const { done, value } = await reader.read();
        if (done) {
            break
        }
        let decodedText = decoder.decode(value);
        // decodedText = decodedText.slice(0, decodedText.length - 1);
        decodedText = JSON.parse(decodedText)
        console.log(decodedText)
        if(decodedText.status === 'error'){
            console.log(decodedText.res)
        }
        // try{
        //     decodedText = JSON.parse(decodedText)
        //     if (decodedText.status === 'Success') {
        //         console.log(decodedText.text)
        //         // callback(decodedText.text)
        //     }else if(decodedText.status === 'Fail') {
        //         break
        //     }
        // }catch (e){
        //     console.log(e)
        //     console.log(decodedText)
        // }
    }
}
send('你好',
    [],
    [])
